﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Diagnostics.Contracts;

namespace WFBot.Framework.Extensions
{
    public static class ObjectExtensions
    {
        public static Dictionary<string, object> ToDictionary(this object instance)
        {
            Contract.Requires(instance != null);

            var dictionary = new Dictionary<string, object>();

            var properties = TypeDescriptor.GetProperties(instance);
            foreach (PropertyDescriptor descriptor in properties)
            {
                dictionary.Add(descriptor.Name, descriptor.GetValue(instance));
            }

            return dictionary;
        }
    }
}
